package mars.activity;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import bear.download.HttpsUtils;
import bear.download.Userread;

import android.app.ExpandableListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SimpleExpandableListAdapter;

public class shareActivity extends ExpandableListActivity{
private Button newtext;
private int c=0;
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.share);
		newtext=(Button)findViewById(R.id.newtext);
		
		HttpsUtils hu=new HttpsUtils();			
		String shareUrl=hu.get("https://www.loushiapp.com/?c=say&a=getothers&hash="+landActivity.hash);
		try{
			SAXParserFactory shareidea = SAXParserFactory.newInstance();
			XMLReader reader=shareidea.newSAXParser().getXMLReader();
			reader.setContentHandler(new Userread());
			reader.parse(new InputSource(new StringReader(shareUrl)));
		}catch(Exception e){
			e.printStackTrace();
		}
		String loushinames[] = Userread.loushiname1.split("\\$");
		String contents[] = Userread.content1.split("\\$");
		String times[] = Userread.time1.split("\\$");
		String loushinames0[]=loushinames;
		for(int t=0;t<loushinames.length;t++){
			for(int j=0;j<loushinames0.length;j++){
				if(loushinames[t].equals(loushinames0[j])){
					loushinames0[j]="";
				}
			}
		}
		
		List<Map<String,String>> groups=new ArrayList<Map<String,String>>();
		Map<String,String> group1=new HashMap<String,String>();
		group1.put("group",getString(R.string.everybody));
		groups.add(group1);	
		for(int i=0;i<Userread.n;i++){
			if(!loushinames[i].equals("")){
		Map<String,String> group=new HashMap<String,String>();
		group.put("group",loushinames[i]);
		groups.add(group);
		c++;
			}
		}
		
		List<Map<String,String>> child1=new ArrayList<Map<String,String>>();
			Map<String,String> child1date= new HashMap<String,String>();
			child1date.put("child","mz");
			child1.add(child1date);
			List<Map<String,String>> child2=new ArrayList<Map<String,String>>();
		Map<String,String> child2date1=new HashMap<String,String>();
		child2date1.put("child","mz" );
		child2.add(child2date1);
		
		List<List<Map<String,String>>> childs=new ArrayList<List<Map<String,String>>>();
		childs.add(child1);
		childs.add(child2);
		
		SimpleExpandableListAdapter sela=new SimpleExpandableListAdapter(
				this, groups, R.layout.groupto, new String[] { "group" }, new int[] { R.id.group },
				childs, R.layout.childto, new String[] { "child" }, new int[] { R.id.child });
	       setListAdapter(sela);	    
	       
	newtext.setOnClickListener(new Button.OnClickListener()
    {
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent=new Intent();
			intent.setClass(shareActivity.this, newtextActivity.class);
			shareActivity.this.startActivity(intent);
		}	
    });
	}
}
